﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TjZheng.Framework;
using TjZheng.SSO.Business;
using TjZheng.SSO.DataEntity;
using TjZheng.Cache;

namespace TjZheng.SSO.Process
{
    public partial class UserProcess
    {
        /// <summary>
        /// 获取并转换用户数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public virtual InvokeResult ConvertUserInfo(string id)
        {
            InvokeResult objInvokeResult = new InvokeResult();
            BizUserInfo objBizUserInfo = new BizUserInfo();
            UserInfo objUserInfo = objBizUserInfo.GetRecordCache("", id.ConvertInt(), TimeSpan.FromSeconds(5));
            if (objUserInfo == null)
            {
                objInvokeResult.ResultCode = "NotExist";
                objInvokeResult.ResultMessage = "对不起，用户不存在";
                return objInvokeResult;
            }
            objUserInfo.Password = string.Empty;
            objInvokeResult.Data = objUserInfo;
            return objInvokeResult;
        }
        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public virtual InvokeResult GetUserInfo(string id)
        {
            InvokeResult objInvokeResult = new InvokeResult();
            BizTempInfo objBizTempInfo = new BizTempInfo();
            TempInfo objTempInfo = objBizTempInfo.GetRecordCache("", TimeSpan.FromSeconds(5), "ObjectId=@ObjectId AND ObjectCode='UserInfo'", "ObjectId".CreateSqlParameters(id));

            if (objTempInfo == null || objTempInfo.EffectiveDate.IsLessThanCurrent())
            {
                objInvokeResult.ResultCode = "LoginInvalid";
                objInvokeResult.ResultMessage = "对不起，您的登录凭据已经失效";
                return objInvokeResult;
            }
            return ConvertUserInfo(id);
        }

    }
}
